﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Library.Utilities;
using DLV.Utilities;

namespace DLV.Data.Entities
{
    public class TicketController
    {
        public int InsertTicket(TicketInfo info)
        {
            return SQL.InsertTicket(info.ConcernId, info.ScheduleId, info.TicketName, info.SortDescription, info.DetailDescription, info.TypeId, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void UpdateTicket(TicketInfo info)
        {
            SQL.UpdateTicket(info.TicketId, info.ConcernId, info.ScheduleId, info.TicketName, info.SortDescription, info.DetailDescription, info.TypeId, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void DeleteTicket(TicketInfo info)
        {
            DeleteTicket(info.TicketId);
        }
        public void DeleteTicket(int ticketId)
        {
            SQL.DeleteTicket(ticketId);
        }
        public TicketInfo GetTicket(int ticketId)
        {
            return CBO.FillObject<TicketInfo>(SQL.GetTicket(ticketId));
        }
        public List<TicketInfo> ListTicket()
        {
            return CBO.FillCollection<TicketInfo>(SQL.ListTicket());
        }
        public DataTable SelectTicket()
        {
            return CBO.ConvertToDataTable(ListTicket(), typeof(TicketInfo));
        }
        public List<TicketInfo> ListTicketByType(int typeId)
        {
            return CBO.FillCollection<TicketInfo>(SQL.ListTicketByType(typeId));
        }
        public DataTable SelectTicketByType(int typeId)
        {
            return CBO.ConvertToDataTable(ListTicketByType(typeId), typeof(TicketInfo));
        }
        public List<TicketInfo> TicketListByConcern(int typeOf,int concernId)
        {
            return CBO.FillCollection<TicketInfo>(SQL.TicketListByConcern(typeOf,concernId));
        }
      
        
        public Dictionary<object, object> ListTicketLookup()
        {
            var users = ListTicket().Where(p=>p.Status==(int)Globals.DocumentStatus.Use).OrderBy(p=>p.TicketName);
            var dicusers = new Dictionary<object, object>();
           
            foreach (TicketInfo info in users)
            {
                    dicusers.Add(info.TicketId, info.TicketName);
                
            }
            return dicusers;
        }
    }
}
